package com.wangzhixuan.service;

import com.wangzhixuan.db.bean.Doctor;
import com.wangzhixuan.db.bean.Product;
import com.wangzhixuan.db.bean.Tag;
import com.wangzhixuan.db.dao.DoctorDao;
import com.wangzhixuan.db.dao.ProductDao;
import com.wangzhixuan.db.dao.TagDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class DoctorService {

    @Autowired
    private DoctorDao doctorDao;
    @Autowired
    private TagDao tagDao;
    @Autowired
    private ProductDao productDao;

    /**
     * Get doctor by doctorId
     *
     * @param doctorId
     * @return
     */
    public Doctor getDoctorById(long doctorId) {
        Doctor doctor = doctorDao.getDoctorById(doctorId);
        return doctor;
    }

    public List<Doctor> getAttentionDoctors(long customerId) {
        List<Doctor> doctors = doctorDao.getAttentionDoctors(customerId);
        return doctors;
    }

    public List<Doctor> getDoctorBySearch(String search) {
        search = "%" + search + "%";
        List<Doctor> doctors = doctorDao.getDoctorBySearch(search);
        return doctors;
    }

    public List<Doctor> getDoctorByDepartment(String deptName) {
        if ("all".equals(deptName)) {
            List<Doctor> doctors = doctorDao.getAllDoctor();
            return doctors;
        } else {
            List<Doctor> doctors = doctorDao.getDoctorByDepartment(deptName);
            return doctors;
        }
    }

    public List<Doctor> getAllDoctor() {
        List<Doctor> doctors = doctorDao.getAllDoctor();
        return doctors;
    }
    public List<Doctor> getDoctorByDepartmentId(long deptId) {
        List<Doctor> doctors = doctorDao.getDoctorByDepartmentId(deptId);
        return doctors;
    }
    public List<Doctor> getDoctorByDepartmentIds(List<Long> ids) {
        List<Doctor> doctors = doctorDao.getDoctorByDepartmentIds(ids);
        return doctors;
    }

    public Doctor getDoctorDetail(long doctorId) {
        Doctor doctor = getDoctorById(doctorId);
        List<Tag> tags = tagDao.getTagsByDoctor(doctorId);
        List<Product> products = productDao.getProductsByDoctor(doctorId);
        doctor.setTags(tags);
        doctor.setProducts(products);
        return doctor;
    }
    public int addAttention(long customerId,long doctorId){
        int num=doctorDao.getAttention(customerId, doctorId);
        if(num>0){
            return num;
        }else{
            return doctorDao.addAttention(customerId, doctorId);
        }
    }
    public int getAttention(long customerId,long doctorId){
        return doctorDao.getAttention(customerId, doctorId);
    }
    
    public int deleteAttention(long customerId,long doctorId){
        return doctorDao.deleteAttention(customerId, doctorId);
    }
}
